package com.mlethe.android.demo.seattable.base;

import androidx.fragment.app.FragmentActivity;

import java.lang.ref.WeakReference;

public class BasePresenter<V extends IView> implements IPresenter<V> {

    protected FragmentActivity mFragmentActivity;
    protected Activity mActivity;

    protected WeakReference<V> mView;

    public BasePresenter(FragmentActivity activity) {
        this.mFragmentActivity = activity;
    }

    public BasePresenter(Activity activity) {
        this.mActivity = activity;
    }

    protected V getView() {
        return mView.get();
    }

    @Override
    public void attachView(V view) {
        mView = new WeakReference<>(view);
    }

    @Override
    public void detachView() {
        if (mView != null) {
            mView.clear();
            mView = null;
        }
    }

    @Override
    public void onCreate() {

    }

    @Override
    public void onStart() {

    }

    @Override
    public void onResume() {

    }

    @Override
    public void onPause() {

    }

    @Override
    public void onStop() {

    }

    @Override
    public void onDestroy() {
        if (mFragmentActivity != null) {
            mFragmentActivity = null;
        }
        if (mActivity != null) {
            mActivity = null;
        }
    }
}
